﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using DataLayer;
using System.Data.SqlClient;

public partial class Widgets_Admin_template : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   {
      using (new EntLib.EntTimedLog(Profile.UserName, GetType().ToString(), Request.QueryString.ToString()))
      {
         if (!Roles.IsUserInRole("Administrator") && Profile.UserName.ToLower() != @"nusstf\cittka")
         {
            EntLib.EntLibHelper.Log_Action(DateTime.Now, "ACCESS DENIED: " + Request.Url, Profile.UserName);
            return;
         }

         /*
         DataTable tbl = new DataTable("tbl");
         tbl.Columns.Add("FileName");
         tbl.Columns.Add("URL");

         DirectoryInfo DI = new DirectoryInfo(Server.MapPath("/logs"));
         foreach (FileInfo FI in DI.GetFiles())
         {
            DataRow row = tbl.NewRow();
            row["FileName"] = FI.Name;
            row["URL"] = "/logs/" + FI.Name;
            tbl.Rows.Add(row);
         }

         dl_Logs.DataSource = tbl;
         dl_Logs.DataBind();
         */
         DataSet DS = new DataSet();
         using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DashboardConnectionString"].ConnectionString))
         {
            using (SqlDataAdapter adapter = new SqlDataAdapter())
            {
               adapter.SelectCommand = new SqlCommand("exec getstatistics", conn);
               adapter.Fill(DS);
            }
         }

         if (DS.Tables.Count > 2)
         {
            GV_Statistics.DataSource = DS.Tables[0];
            GV_Statistics.DataBind();

            GV_Users.DataSource = DS.Tables[1];
            GV_Users.DataBind();

            GV_Widgets.DataSource = DS.Tables[2];
            GV_Widgets.DataBind();
         }
      }
   }
}
